//
//  RomotionsCell.swift
//  d11
//
//  Created by peale on 2018/8/1.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class RomotionsCell: UITableViewCell {
    var  bgView : UIView?
    var  iconImageView : UIImageView?
    var  typeBtn : UIButton?
    var titleLabel : UILabel?
     var statusLabel : UILabel?
     var  clickBtn : UIButton?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.contentView.backgroundColor = HexRGBAlpha(0xEFF0F1, 1)
        self.bgView = UIView.init()
         self.bgView?.backgroundColor = UIColor.white
        self.contentView.addSubview(self.bgView!)
        self.bgView?.snp.makeConstraints{(make) in
            make.left.equalTo(10)
            make.right.equalTo(-10)
         //   make.height.equalTo(182)
             make.height.equalTo(125)
            make.top.equalToSuperview().offset(4)
        }
        
        self.iconImageView = UIImageView.init()
        self.iconImageView?.image = imageNamed("img_default_banner")
        self.iconImageView?.contentMode = .scaleToFill
//        self.iconImageView?.isUserInteractionEnabled = true;
//       self.iconImageView?.highlightedImage = ToolHelper.imageWithColor(color: UIColor.lightGray, size: CGSize(width: kScreenWidth, height: 75))
//        self.iconImageView?.isHighlighted = true
        self.bgView?.addSubview(self.iconImageView!)
        self.iconImageView?.snp.makeConstraints{(make) in
             make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.top.equalToSuperview()
           // make.height.equalTo(122)
            make.height.equalTo(65)
        }
        
        self.typeBtn = UIButton.init(type: .custom)
        self.typeBtn?.setTitleColor(UIColor.white, for: .normal)
        self.typeBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 10)
        self.typeBtn?.setBackgroundImage(imageNamed("icon_promotions_cell_type"), for: .normal)
        self.typeBtn?.isUserInteractionEnabled=false
        self.contentView.addSubview(self.typeBtn!)
        self.typeBtn?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(10)
            make.width.equalTo(78.5)
            make.height.equalTo(28)
        }
        
        self.clickBtn =  UIButton.init(type: .custom)
        
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        self.clickBtn?.layer.addSublayer(layerGradient)
        self.clickBtn?.layer.cornerRadius = 5;
        self.clickBtn?.layer.masksToBounds = true
        self.clickBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        self.clickBtn?.setTitle("点击\n查看", for: .normal)
        self.clickBtn?.titleLabel?.numberOfLines = 2
        self.clickBtn?.isUserInteractionEnabled=false
        self.bgView?.addSubview(self.clickBtn!)
        self.clickBtn?.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(40)
            make.height.equalTo(40)
            make.bottom.equalToSuperview().offset(-10)
        }
        
        self.titleLabel = UILabel.init()
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.bgView?.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalTo((self.clickBtn?.snp.left)!).offset(-10)
            make.height.equalTo(20)
            make.top.equalTo((self.iconImageView?.snp.bottom)!).offset(10)
        }
        
        self.statusLabel = UILabel.init()
        self.statusLabel?.textColor = HexRGBAlpha(0x999999, 1)
        self.statusLabel?.font = UIFont.systemFont(ofSize: 14)
        self.statusLabel?.textAlignment = NSTextAlignment.left
        self.bgView?.addSubview(self.statusLabel!)
      
        self.statusLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalTo((self.clickBtn?.snp.left)!).offset(-10)
            make.height.equalTo(20)
            make.top.equalTo((self.titleLabel?.snp.bottom)!).offset(5)
        }
    }
   // "http://m.manbet5858.com/iimg/i201806cb4e59d36cc74234ad0cd4b98a8f6bca.png"
    func setData(dict :[String:Any]) -> Void {
        let domain :String =  UserDefaults.standard.value(forKey: DefaultKey.USER_DOMAIN) as! String
        let domainScheme :String = UserDefaults.standard.string(forKey: DefaultKey.DOMAIN_SCHEME)!
        let imgurl : String =  dict["cover"] as! String
        let url = URL(string: "\(domainScheme)://\(domain)/iimg/\(imgurl)")
        self.iconImageView?.sd_setImage(with: url, placeholderImage: imageNamed("img_default_banner"), options: SDWebImageOptions.refreshCached, completed: nil)
        self.typeBtn?.setTitle(dict["actypename"] as? String, for: .normal)
        self.titleLabel?.text = dict["actname"] as? String
        if(UserHelper.getLoginStatus()){
            if dict["activeapply"] as? String ?? "0" == "0" {
                self.statusLabel?.text =  dict["nonactiveapplybtn"] as? String ?? "敬请期待"
            }else if dict["activeapply"] as? String ?? "0" == "1"{
                   self.statusLabel?.text =  dict["show"] as? String ?? ""
            }
        }else{
            self.statusLabel?.text = "申请参与"
        }
        
        if self.statusLabel?.text == "申请参与" {
             self.statusLabel?.textColor = UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1)
        }else
        {
             self.statusLabel?.textColor = HexRGBAlpha(0x999999, 1)
        }
    }
}
